"use strict";
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "@/plugins";
import "@/styles/index.less";
import directives from "@/directive";

Vue.use(directives); //自定义指令

Vue.config.productionTip = false;
Vue.config.errorHandler = function f(err, vm) {
  let path = "";
  if (vm && vm.$route) {
    path = vm.$route.fullPath;
  }
  console && console.error(path, err);
};

// 路由拦截器处理token失效，接口报错
router.beforeEach((to, from, next) => {
  if (!store.getters.token && to.path !== "/login") {
    router.replace("/login");
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount("#app");
